# sdpMAIN.py
# AUTHOR: LEWIS MARHIN
# PURPOSE: To test and prototype GUI for CP304x Student Day Planner project.
# CONTROLS: RIGHT SOFT KEY : Exit

import sys
# This allows source files to be located in various positions and still working
sys.path.append("c:\\python")
sys.path.append("e:\\python")
sys.path.append("c:\\python\sdp")
sys.path.append("e:\\python\sdp")
sys.path.append("c:\\resource")
sys.path.append("e:\\resource")

import e32 # Nokia
import appuifw # Nokia
import Cursor
import KeyHandler
import DrawHandler
import Ops
import sysinfo # Nokia/Python
from appuifw import *
from graphics import *
from key_codes import *

class GUI:
	def __init__(self):
		# Used to draw numbers down the side (for demonstration purposes)
		self.hours = ["7","8","9","10","11","12","13","14","15","16","17","18","19","20","21"]
		self.img = Image.new(sysinfo.display_pixels()) # Tuple input
		self.cursor = Cursor.NormalType
		self.amount = 0.5 # MOVE INITIALIZATION

	def run(self):
		keyboard = KeyHandler.Keyboard()
		keys = KeyHandler.Keys()

		def display(rect):
			canvas.blit(self.img) # Required line that I couldn't get out of using
		
		canvas = appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback = display) # Create new canvas
		appuifw.app.body = canvas # Sets the screen to show the canvas object
		appuifw.app.screen = 'full' # Fullscreen mode

		# This function works like in OpenGL, it will loop
		while Ops.Phone.isRunning():
			self.img.clear(0xFFFFFF) # clears canvas for redraw (probably)
			DrawHandler.Draw.event(0, True, self.img)
			DrawHandler.Draw.event(1, False, self.img)
			DrawHandler.Draw.event(2, False, self.img)
			cursor.moveCursor(keys.arrows(self.amount, self.cursor))
			DrawHandler.Draw.cursor(self.img)
			DrawHandler.Draw.mainScreen(self.img)
			
			canvas.blit(self.img)
			canvas.blit(self.img)
			canvas.blit(self.img)
			canvas.blit(self.img)
			e32.ao_yield() # Allows priority to be taken from immortal loop.
		
		Ops.Phone.lockWait()
		
	run = classmethod(run)
